package com.demo.sbaclient.controller;

import com.alibaba.fastjson2.JSONObject;
import com.demo.sbaclient.service.TestService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Bruce
 * @date 2025/7/27 19:53
 */
@RestController
@RequestMapping("test")
public class TestController {

    @Resource
    private TestService testService;

    @GetMapping("/hello")
    public String hello() {
        return "hello world";
    }

    @GetMapping("/cache")
    public List<String> cache() {
        return testService.cache();
    }

    @GetMapping("/get/{id}")
    public String get(@PathVariable("id") Long id) {
        String s = testService.get(id);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result", s);
        return jsonObject.toJSONString();
    }

    @GetMapping("/update/{id}")
    public String update(@PathVariable("id") Long id) {
        testService.update(id);
        return "success";
    }

}
